<?php 
//this php file implements the upload file inside a comment
session_start();

 $_SESSION['iframe']=1; 
if(!isset($_SESSION['user']))
{
 	echo "<script > window.location.href='index.php';</script>" ;
}

require_once('./config.php');
require_once('./inc/database.php');
require_once('./inc/functions.php');

require_once('./class/class.user.php');
require_once('./class/class.project.php');
require_once('./class/class.task.php');
require_once('./class/class.project_access_details.php');
require_once('./class/class.permissions.php');
require_once('./class/class.comments.php');

/*********************************************************************************************/
?>

<script src="inc/js/jquery-1.7.min.js"  type="text/javascript"></script>
<script src="inc/js/jquery-ui-1.8.16.custom.min.js"  type="text/javascript"></script>
<script src="inc/js/core.js" type="text/javascript"></script>
<script src="inc/js/jquery.validate.js" type="text/javascript"></script>
<?php

//upload files in comment window
if(isset($_FILES['new_print_screen']))
{   
?> <script> 
function preloader()
					   	{
						  	$("#loading").css('display','none');	
						}
 window.onload = preloader;
 </script><?php 
$id_project=$_GET['project'];
	$path='./upload/';
	if(isset($_GET['task'])){$id_task=$_GET['task'];}
	$arr=array(
				"image/jpeg"=>"jpeg",
				"image/png"=>"png",
				"image/gif"=>"gif",
				"application/vnd.openxmlformats-officedocument.wordprocessingml.document"=>"doc",
				"application/pdf"=>"pdf",
				"text/plain"=>"txt",
				"application/vnd.ms-powerpoint"=>"ppt",
				"application/vnd.openxmlformats-officedocument.presentationml.presentatio"=>"pptx",
				"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"=>"xlsx"
				
	);
        //prepare path to upload the file into
	$type=$_FILES["new_print_screen"]["type"]; //type: task file/comment file/project file
	if(!is_dir($path.$id_project))
	{
		 mkdir($path.$id_project);
	}
 
	$path.=$id_project.'/';
	
	   $path.='.'.$arr[$type];
           
	if(!move_uploaded_file($_FILES["new_print_screen"]["tmp_name"],$path)){echo 'הקובץ לא עלה';};
	 $txt='./upload/'.$_SESSION['user'].'-'.$_SERVER['REMOTE_ADDR'].'com.txt';
	 $fp = fopen($txt, 'w');
	fwrite($fp, $path);
	fclose($fp);
		?><script>
		               
          </script>
<?php 
}
?>

<style>
*{font-family:Arial, Helvetica, sans-serif;}

div#loading {
    background: url("./style/images/load.gif") no-repeat scroll 0 0 transparent;
    cursor: wait;
    display: none;
    height: 38px;
    margin: auto;
    position: absolute;
    right: 217px;
    top: 21px;
    width: 36px;
    z-index: 1000;
    }
	#form_add_task{
	float:right;
	height:16px;	
}
#form_add_task label{
	float:right;
	color: #609395;
	line-height:16px;
	font-size:14px;	
	font-weight:bold;
}
#form_add_task input{
	visibility:hidden;
	width:0;		
}
#printscreen_btn{
	float:right;
	margin-right:5px;
	width:120px;
	text-align:center;
	height:18px;
	border:1px solid #609395;
	font-weight:bold;
	font-size:14px;
	text-decoration:none;
	line-height:18px;
	color:#609395;
	font-family:Arial, Helvetica, sans-serif;
	cursor:pointer;
	-webkit-box-shadow: inset 0px 0px 2px 1px rgba(96, 147, 149, 0.5);
	-moz-box-shadow: inset 0px 0px 2px 1px rgba(96, 147, 149, 0.5);
	box-shadow: inset 0px 0px 2px 1px rgba(96, 147, 149, 0.5); 		
}
#printscreen_btn:hover{
	-webkit-box-shadow: inset 0px 0px 2px 2px rgba(96, 147, 149, 0.5);
	-moz-box-shadow: inset 0px 0px 2px 2px rgba(96, 147, 149, 0.5);
	box-shadow: inset 0px 0px 2px 2px rgba(96, 147, 149, 0.5); 
}

#loading{
	float:right;
		
}
#form_add_task p
{
 font-size:12px;
 margin:0 auto;
 color:#609395;	
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<input id="hid_I" name="hid_I" type="hidden" value="0"  />
<form id="form_add_task" name="form_add_task" enctype="multipart/form-data" method="post" action="">
 <p >txt,doc,ppt,pdf,xlsx -אפשר לעלות רק קבצים עם סיומת </p>
 <label for="new_print_screen" class="color_turkiz">:הוספת קובץ</label> 
 <input id="new_print_screen" name="new_print_screen" type="file" value="<?php echo $path; ?>" />
 <div id="printscreen_btn"> בחר קובץ ...</div>
 <div id="loading"></div> 
  </form>
         
<script>
 
$(document).ready(function(e) {
   $('#form_add_task').validate({ 
		  
	         rules : {
							 
					  },
			messages : 
					  {
									  
					  },
		  submitHandler: function(form) 
					 {    
					       var ext=$('#new_print_screen').val().split('.').pop().toLowerCase(); 
								 
							var allow = new Array('jpg','jpeg','gif','png','txt','pdf','doc','docx','ppt','pptx','xlsx');//'gif','png', 
								
					 if(jQuery.inArray(ext, allow) == -1 )
						{
						alert("הפורמט של הקובץ צריך להיות :jpeg,txt,png,gif,pdf,doc,docx,ppt,pptx,xlsx");
						 return false();
						}
						else 
						{
						 form.submit();	
						}
						
					 
					  
					 }
								 
   });
   $('#new_print_screen').change(function(){
	  
	   $('#form_add_task').submit();
	   $("#loading").css('display','block');	
	  
                     
	   });
   
});

$("#form_add_task div").click(function(e) {
    $("#new_print_screen").click();
});
</script>                
 